<?php
$mysqli=new mysqli(    '127.0.0.1',
    'root',
    '7b3eee1c29',
    'baidu',
    '3306');
if ($mysqli->connect_error)
{
    exit('error');
}
//设置字符集
$mysqli->query("SET NAMES UTF8");

/*$mysqli->real_escape_string();
addslashes();*/


//$mysqli->query("INSERT INTO `file`(statu) VALUES(1)");
//$mysqli->query("UPDATE `file` SET statu=11 WHERE uid=3");
/*$result=$mysqli->query("SELECT * FROM `file`");//正式的代码最好不要出现*号
if ($result)
{
    while ($row=$result->fetch_assoc())
    {
        var_export($row);
    }
    $result->free();//
}*/


//begin transaction 命令启动一个事务处理
$bool=$mysqli->begin_transaction();
if ($bool)
{
    try
    {
        $bool=$mysqli->query('INSERT INTO `task`  values(5,6,7)');
        if ($bool)throw new Exception('mysqli error');

        //提交
        $mysqli->commit();
        echo 'ok';
    }catch (Exception $e)
    {
        //回滚
        $mysqli->rollback();
        echo $e->getMessage();
    }
}else{
    echo '开启失败';
}





/*$mysqli->close();
echo 'ok';*/